<template>
  <!-- workflow form -->
  <el-form
    ref="workflow"
    :model="workflowform"
    :rules="workflowrules"
    label-width="100px"
    label-position="right"
  >
    <el-form-item label="所属项目" prop="project_name">
      <el-input v-model="currentProject.project_name" disabled></el-input>
    </el-form-item>
    <el-form-item label="所属文件夹" prop="folder">
      <el-input v-model="folderName" disabled></el-input>
    </el-form-item>
    <el-form-item label="邮箱" prop="email">
      <el-input v-model="workflowform.email"></el-input>
    </el-form-item>
    <el-form-item label="工作流名称" prop="name">
      <el-input v-model="workflowform.name"></el-input>
    </el-form-item>
    <el-form-item label="工作流描述" prop="description">
      <el-input v-model="workflowform.description" :rows="6" type="textarea"></el-input>
    </el-form-item>
  </el-form>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "WorkflowCreate",
  props: {
    folderId: String,
    folderName: String
  },
  data() {
    return {
      workflowform: {
        project_id: "",
        folder_id: "",
        name: "",
        description: "",
        content: {}
      },
      workflowrules: {
        name: [{ required: true, message: "请输入工作流名称", trigger: "blur" }],
        description: [{ required: true, message: "请输入工作流描述", trigger: "blur" }],
        email: [{ type: "email", message: "请输入正确的邮箱地址", trigger: "blur" }],
      }
    };
  },
  computed: {
    ...mapState({
      currentProject: ({ project }) => {
        return project.currentProject || {};
      }
    })
  },
  methods: {
    validator() {
      return new Promise((resolve, reject) => {
        this.$refs.workflow.validate(valid => {
          resolve(valid);
        });
      });
    },
    save() {
      let formData = Object.assign({}, this.workflowform, {
        project_id: this.currentProject.id,
        folder_id: this.folderId
      });
      return this.$http.workflow.addWorkflow(formData);
    },
    clearForm() {
      this.workflowform.description = "";
      this.workflowform.name = "";
      this.workflowform.email = ""
    }
  }
};
</script>
